function handleRrorMinLength(values) {
  const valueArr = values.split(' ').map(Number);
  let map = new Map();
  let max = 0;
  let maxList = [];
  let min = valueArr.length;
  for(let i = 0; i<valueArr.length; i++) {
    let errorCode = valueArr[i];
    if(map.has(errorCode)) {
      map.set(errorCode, map.get(errorCode) + 1)
    } else {
      map.set(errorCode, 1)
    }
    max = Math.max(max,map.get(errorCode))
  }
  for(let [key,value] of map) {
    if(value === max) {
      maxList.push(key);
    }
  }
  for(let j = 0; j<maxList.length; j++) {
    let start = valueArr.indexOf(maxList[j]);
    let end = valueArr.lastIndexOf(maxList[j]);
    min = Math.min(min, end-start+1);
  }
  console.log(min)
}
handleRrorMinLength('1 2 2 4 2 1 1')